import {emojiMap} from '@/assets/constant/emojis'

/**
 * 去掉 省|市|直辖市|自治区
 * @param address 地址
 */
export function parseAddress (address: string): string {
  let regex = /(省|市|直辖市|自治区)$/g
  return address.replace(regex, '')
}

/**
 *  获取当前时间
 * @param full 是否获取 时分秒
 */
export function getCurDate (full = false) {
  const date = new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate()
  let hours = date.getHours()
  let minutes = date.getMinutes()
  let seconds = date.getSeconds()
  return full ? `${year}-${month}-${day} ${hours}:${minutes}:${seconds}` : `${year}-${month}-${day}`
}


/**
 * 聊天室内容处理
 * @param content
 */
export function dealEmoji (content: string): string {
  let ret = ''
  let n = content.length
  for (let i = 0; i < n; i++) {
    let c = content[i]
    if (c === '/') {
      let emoji = content.substring(i, i + 4)
      if (emojiMap.has(emoji)) {
        ret += `<span style='display: inline; font-size: 16px'>${emojiMap.get(emoji).emoji}</span>`
        i += 3
      }
    } else {
      ret += c
    }
  }
  return ret
}

// export function dealEmoji (chatList: ChatListItem[]): ChatListItem[] {
//     for (let chatListItem of chatList) {
//         let content = ''
//         let n = chatListItem.content.length
//         for (let i = 0; i < n; i++) {
//             let c = chatListItem.content[i]
//             if (c === '/') {
//                 let emoji = chatListItem.content.substring(i, i + 4)
//                 if (emojiMap.has(emoji)) {
//                     content += `<span style='display: inline; font-size: 16px'>${emojiMap.get(emoji).emoji}</span>`
//                     i += 3
//                 }
//             } else {
//                 content += c
//             }
//         }
//         chatListItem.content = content
//     }
//     return chatList
// }
